package DataBaseTest;

import java.sql.Date;
import java.util.ArrayList;

import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

import DataBase.DB_Factory;
import DataBaseInterface.PromotionServerInterface;
import Po.Credits;
import Po.Discount;
import Po.Equivalent;
import Po.Message;
import Po.Promotion;
import Po.Result;

public class PromotionServerTest {

	PromotionServerInterface test;
	
	@Before
	public void setUp() throws Exception {
		test  =DB_Factory.getPromotionServerDB();
	}

	@After
	public void tearDown() throws Exception {
	}

	@Test
	public final void testGet() {
		ArrayList<Promotion> list = test.getAllPromotionList();
		Assert.assertTrue(list.size() == 4);
		Assert.assertTrue(list.get(0).ID == 1);
	}
	
	@Test
	public final void testGetPromotion() {
		ArrayList<Promotion> l= test.getCustomerPromotionList(1);
		Assert.assertTrue(l.size() == 8);
	}
	
	@Test
	public final void testPresent() {
		ArrayList<Promotion> l = test.getAllPromotionList();
		Message m  = test.presentPromotion(l.get(0), 1, 5);
		Assert.assertTrue(m.result == Result.Success);
	}
	
	@SuppressWarnings("deprecation")
	@Test
	public final void testAddDis(){
		Message m = test.addDiscountPromotion(new Discount(new Date(111,12,3), 
				new Date(111,12,3), new Date(111,12,3), new Date(111,12,3), 5, 0.2));
		Assert.assertTrue(m.result == Result.Fail);
	}
	@SuppressWarnings("deprecation")
	@Test
	public final void testAddE(){
		Message m = test.addEquivalentPromotion(new Equivalent(new Date(111,12,3), 
				new Date(111,12,3), new Date(111,12,3), new Date(111,12,3), 6,8, 0.2));
		Assert.assertTrue(m.result == Result.Fail);
	}
	@SuppressWarnings("deprecation")
	@Test
	public final void testModifyDiscunt(){
		Message m = test.modifyDiscountPromotion(new Discount(new Date(111,12,3), 
				new Date(111,12,3), new Date(111,12,3), new Date(111,12,3), 5, 0.8));
		Assert.assertTrue(m.result == Result.Success);
	}
	@SuppressWarnings("deprecation")
	@Test
	public final void testModifyE(){
		Message m = test.modifyEquivalentPromotion(new Equivalent(new Date(111,12,3), 
				new Date(111,12,3), new Date(111,12,3), new Date(111,12,3), 6,80, 0.2));
		Assert.assertTrue(m.result == Result.Success);
	}
	@Test
	public final void testModifyCredits(){
		Credits c = new Credits();
		c.creditsToMoneyRate = 100;
		c.moneyToCreditsRate = 1000;
		Message m = test.modifyCredits(c);
		Assert.assertTrue(m.result == Result.Success);
				
	}
	@Test 
	public final void testGetCredits(){
		Credits c = test.getCredits();
		Assert.assertTrue(c.creditsToMoneyRate == 100);
		Assert.assertTrue(c.moneyToCreditsRate == 1000);
	}
}
